﻿using System;
using System.Threading;
using System.Collections.Generic;

namespace Eventless
{
    public static class Computations
    {
        private static readonly ThreadLocal<Stack<Action<IReadable>>> Stack =
            new ThreadLocal<Stack<Action<IReadable>>>(() => new Stack<Action<IReadable>>());

        public static void Push(Action<IReadable> listener)
        {
            Stack.Value.Push(listener);
        }

        public static void Pop()
        {
            Stack.Value.Pop();
        }

        public static void Reading(IReadable obs)
        {
            if (Stack.Value.Count != 0)
                Stack.Value.Peek()(obs);
        }
    }
}